<?php
/**
 * Created by PhpStorm.
 * User: yhf
 * Date: 2019-04-19
 * Time: 11:40
 */

namespace app\api\controller\v1;

use app\api\model\Tp;
use app\api\validate\AddUser;
use app\api\service\AddUser as UserService;
use app\lib\exception\UserException;
use app\api\service\Token as TokenService;

class User
{
    /**
     * @url xcx/Tpadd
     * 学生投票
     * @param
     * $date {string}
     * @return
     * true （成功信息）
     * false （抛出异常）
     */
    public function getTpAdd($date) {
        // 验证必须传值，非空
        (new AddUser())->goCheck();

        // 获取id
        $uid = TokenService::getCurrentUid();

        $up = UserService::getTpAdd($uid,$date);

        if ($up) {
            return [
                'errorCode' => 0,
                'msg' => '投票成功'
            ];
        } else {
            return [
                'errorCode' => 203,
                'msg' => '投票失败'
            ];
        }
    }



    public function getData() {
        return Tp::get();
    }
}
